package com.da.landlord;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Where;

import com.googlecode.cswish.annotation.cm;
import com.ra.landlord.LandlordOwner;
import com.ra.landlord.LandlordOwnerUser;


/**
 * 费用帐单
 * @author Perter.Z
 *
 */
@Entity
@Table(name="da_dachargebill")
public class DaChargeBill implements LandlordOwner{
	
	private Integer id;
	
	@cm("费用所对应的房间")
	private DaRoom room;
	
	@cm("是哪个合约产生的费用")
	private DaAgreement agreement;
	
	@cm("所属房东")
	private LandlordOwnerUser landlordUser;
	
	@cm("应收费用项总额")
	private BigDecimal amountRecv;
	
	@cm("实收费用项总额")
	private BigDecimal amountActual;
	
	@cm("余额")		
	private BigDecimal balance;
	
	@cm("上次余额")	//transient		
	private BigDecimal prevBalance;

	@cm("帐单产生日期") 
	private Date dateActual;
	
	@cm("帐单明细")
	private List<DaChargeItem> chargeItems;
	
	@cm("帐单备注")
	private String remark;
	
	
	@Id
	@GeneratedValue
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@ManyToOne
	public LandlordOwnerUser getLandlordUser() {
		return landlordUser;
	}

	public void setLandlordUser(LandlordOwnerUser landlordUser) {
		this.landlordUser = landlordUser;
	}

	public BigDecimal getAmountRecv() {
		return amountRecv;
	}

	public void setAmountRecv(BigDecimal amountRecv) {
		this.amountRecv = amountRecv;
	}

	public BigDecimal getAmountActual() {
		return amountActual;
	}

	public void setAmountActual(BigDecimal amountActual) {
		this.amountActual = amountActual;
	}

	public Date getDateActual() {
		return dateActual;
	}

	public void setDateActual(Date dateActual) {
		this.dateActual = dateActual;
	}

	public BigDecimal getBalance() {
		return balance;
	}

	public void setBalance(BigDecimal balance) {
		this.balance = balance;
	}

	
	@OneToMany(targetEntity = DaChargeItem.class, mappedBy = "chargeBill", cascade=CascadeType.ALL)
	@Where(clause="status=1")
	@OrderBy("chargeType asc, id desc")
	public List<DaChargeItem> getChargeItems() {
		return chargeItems;
	}

	public void setChargeItems(List<DaChargeItem> chargeItems) {
		this.chargeItems = chargeItems;
	}

	@ManyToOne
	public DaRoom getRoom() {
		return room;
	}

	public void setRoom(DaRoom room) {
		this.room = room;
	}
	
	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}
	
	@ManyToOne(cascade=CascadeType.REFRESH)
	public DaAgreement getAgreement() {
		return agreement;
	}

	public void setAgreement(DaAgreement agreement) {
		this.agreement = agreement;
	}

	@Transient
	public BigDecimal getPrevBalance() {
		return prevBalance;
	}

	public void setPrevBalance(BigDecimal prevBalance) {
		this.prevBalance = prevBalance;
	}
	
}
